﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
namespace WinnerCMS.Common
{
    /// <summary>
    /// 资源文件帮助类
    /// </summary>
    public class ResHelper
    {
        /// <summary>
        /// 取得资源
        /// </summary>
        /// <param name="dll">dll的地址</param>
        /// <param name="resourceFullName">资源文件,要包括命名空间和文件的后缀名</param>
        /// <returns></returns>
        /// <remarks>调用例子：ResHelper.GetResourceContents("WinnerCMS.Common", "WinnerCMS.Common.PageBase.ValidatorUpdateDisplay.res");</remarks>
        public static string GetResourceContents(string dll, string resourceFullName)
        {

            Stream stream1 = Assembly.Load(dll).GetManifestResourceStream(resourceFullName);

            using (StreamReader reader1 = new StreamReader(stream1))
            {

                return reader1.ReadToEnd();
            }

        }


        /// <summary>
        /// 取得资源
        /// </summary>
        /// <param name="dll">dll的地址</param>
        /// <param name="resourceFullName">资源文件,要包括命名空间和文件的后缀名</param>
        /// <returns></returns>
        /// <remarks>调用例子：ResHelper.GetResourceContents("WinnerCMS.Common", "WinnerCMS.Common.PageBase.ValidatorUpdateDisplay.res");
        /// 用完需要关闭 reader。
        /// </remarks>
        public static StreamReader GetResourceStreamReader(string dll, string resourceFullName)
        {
            Stream stream1 = Assembly.Load(dll).GetManifestResourceStream(resourceFullName);

            StreamReader reader1 = new StreamReader(stream1);

            return reader1;

        }
    }
}